function merge(obj1, obj2) {
  const result = Object.assign({}, obj1, obj2);
  for (const key in result) {
    if (typeof result[key] === "object" && result[key] !== null) {
      if (Array.isArray(result[key])) {
        result[key] = [...obj1[key], ...obj2[key]];
      } else if (
        typeof obj1[key] === "object" &&
        typeof obj2[key] === "object"
      ) {
        result[key] = merge(obj1[key], obj2[key]);
      }
    }
  }
  return result;
}

export default merge;
